package com.starkuz.mailsender;


import com.starkuz.dto.MarketerDto;

import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.util.Properties;
//для отправки нам сообщений заазов в маркетере
public class MarketerSender {

    private final static String TEMPLATE_MESSAGE_BEGIN = "Пришел заказ на MARKETER:  \n";
    private final static String NAMECUST = "Имя -  ";
    private final static String LOGINCUST = "Email -  ";
    private final static String WEBSITE = "Сайт -  ";
    private final static String PACKAGEEM = "Пакет внедрения -  ";
    private final static String ENTER = "\n";


    public static void sendOrderOnMarketer(MarketerDto marketerDto){
       String nameCust = marketerDto.getNameCust();
       String loginCust = marketerDto.getLoginCust();
       String website = marketerDto.getWebsite();
       String packageEm = marketerDto.getPackageEm();

        Properties props = new Properties();
        props.put("mail.smtp.host", "smtp.gmail.com");
        props.put("mail.smtp.socketFactory.port", "465");
        props.put("mail.smtp.socketFactory.class",
                "javax.net.ssl.SSLSocketFactory");
        props.put("mail.smtp.auth", "true");
        props.put("mail.smtp.port", "465");

        Session session = Session.getDefaultInstance(props,
                new Authenticator() {
                    protected PasswordAuthentication getPasswordAuthentication() {
                        return new PasswordAuthentication("vovix@alobov.ru","Yulya1811");
                    }
                });

        try {

            Message message = new MimeMessage(session);
            message.setFrom(new InternetAddress("vovix@alobov.ru"));
            message.setRecipients(Message.RecipientType.TO,
                    InternetAddress.parse("vmyusupov@gmail.com"));
            message.setSubject("Заказ на MARKETER");
            String mess = TEMPLATE_MESSAGE_BEGIN +
                    NAMECUST + nameCust + ENTER +
                    LOGINCUST + loginCust + ENTER +
                    WEBSITE + website + ENTER +
                    PACKAGEEM + packageEm + ENTER;
            message.setText(mess);
            Transport.send(message);
        } catch (MessagingException e) {
            throw new RuntimeException(e);
        }
    }


}
